package name.huzhenbo.java.serialization;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

class Foo extends AbstractFoo implements Serializable {

    private static final long serialVersionUID = 341341324132L;

    public Foo(int x, int y) {
        super(x, y);
    }

    private void readObject(ObjectInputStream is) throws ClassNotFoundException, IOException {
        is.defaultReadObject();

        // these are necessary for read the data of object. Otherwise the data is always 0 which is got by defaultReadObject.
        this.setX(is.readInt());
        this.setY(is.readInt());
    }

    private void writeObject(ObjectOutputStream os) throws IOException {
        os.defaultWriteObject();

        // these are necessary for write the data of object.
        os.writeInt(this.getX());
        os.writeInt(this.getY());
    }
}
